<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bookeditor写书示例</title>
    <link rel="stylesheet" href="..//plugins/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="..//plugins/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="..//plugins/bootstrap-treeview/bootstrap-treeview.min.css">
    <link rel="stylesheet" href="..//plugins/katex/katex.css">
    <link rel="stylesheet" href="..//plugins/codemirror/lib/codemirror.css">
    <link rel="stylesheet" href="..//bookeditor.css">
</head>
<body>

<div id="editor-wraper" class="editor-wraper">

</div>

<script src="../plugins/jquery.min.js"></script>
<script src="../plugins/bootstrap/js/bootstrap.js"></script>
<script src="../plugins/bootstrap-treeview/bootstrap-treeview.js")}}"></script>
<script src="../plugins/sortable/Sortable.js")}}"></script>
<script src="../plugins/katex/katex.js"></script>
<script src="../plugins/prettify.min.js"></script>
<script src="../plugins/codemirror/lib/codemirror.js"></script>
<script src="../plugins/codemirror/addon/mode/overlay.js"></script>
<script src="../plugins/codemirror/mode/markdown/markdown.js"></script>
<script src="../plugins/codemirror/mode/gfm/gfm.js"></script>
<script src="../plugins/marked/marked.js"></script>
<script src="../plugins/mousetrap/mousetrap.js"></script>
<script src="../bookeditor.js"></script>

<script>

var values = {};

// 当选中目录时调用该函数
function selectCatalog(old, catalog, after){
    var oldNodeid = old.attr("data-nodeid"),
        nodeid = catalog.attr("data-nodeid");
    values[oldNodeid] = this.getValue();
    var value = (typeof values[nodeid]==="undefined") ? "" : values[nodeid];
    after(value);
    // 一定要返回false，否则bookeditor会在内部重复调用after函数
    return false;
};

function new_editor(markdown){
    // 目录结构
    var catalogs = [
        {href: "#", title: "章节1", is_dir: false},
        {href: "#", title: "章节2", is_dir: true, catalogs: [
                {href: "#", title: "章节2-1", is_dir: false},
                {href: "#", title: "章节2-2", is_dir: false},
            ]},
        {href: "#", title: "章节3", is_dir: false, selected: true},
        {href: "#", title: "章节4", is_dir: true},
    ];

    var options = {
        wraperId: "editor-wraper",
        save: false,
        full: true,
        markdown: markdown,
        catalog: true,
        catalogs: catalogs,
        event: {
            selectCatalog: selectCatalog,
        }
    };
    editor = bookeditor(options);
}

new_editor("# Bookeditor\n 在线写书");

</script>


</body>
</html>
